package j2024.j202407;

import java.io.IOException;
import java.util.*;

public class j0717 {
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        PriorityQueue<Long> q = new PriorityQueue<>((a,b)-> Math.toIntExact(b - a));
        for (int i = 0; i < n; i++) {
            q.offer(in.nextLong());
        }
        List<Long> list = new ArrayList<>();

        int j = 0;
        while(!q.isEmpty()&&j<k){
            long max = q.peek();
            if(max%2==0){
                max = q.poll();
                max/=2;
                q.offer(max);
            }else {
                while(!q.isEmpty()&&q.peek()%2!=0){
                    list.add(q.poll());
                }
                if(q.isEmpty()){
                    break;
                }
                max = q.poll();
                max/=2;
                q.offer(max);
            }
            j++;
        }
        for (int i = 0; i < list.size(); i++) {
            q.offer(list.get(i));
        }
        list.clear();
        long ret = 0;
        while(!q.isEmpty()){
            ret+=q.poll();
        }
        System.out.println(ret);
    }
    public static void main2(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int[] ret = new int[2];
        int min = Integer.MAX_VALUE;
        int left = 0,right = 0;
        int num = 0;
        while(right<n){
            num+=a[right];
            while(num>=x){
                if(min>right-left+1){
                    ret[0] = left;
                    ret[1] = right;
                    min = right-left+1;
                }
                num-=a[left];
                left++;
            }
            right++;
        }
        System.out.println((ret[0]+1)+" "+(ret[1]+1));
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] s = str.split(" ");
        for (int i = 0; i < s.length; i++) {
            System.out.print(s[i].charAt(0)>='a'?(char)(s[i].charAt(0)-32):s[i].charAt(0));
        }
    }
    //双指针
    //283
    public void moveZeroes(int[] nums) {
        int cur = 0,des = -1;
        while(cur<nums.length){
            if(nums[cur]==0){
                cur++;
            }else {
                int tmp = nums[cur];
                nums[cur] = nums[++des];
                nums[des] = tmp;
            }
        }
    }
    //1089
    public void duplicateZeros(int[] arr) {
        int cur = 0,des = 0;
        while(cur<arr.length){
            if(arr[des] == 0){
                des+=2;
            }
            else {
                des++;
            }
            cur++;
            if(des>=arr.length-1){
                break;
            }
        }
        if(des>arr.length-1){
            des-=2;
            cur--;
            arr[arr.length-1] = 0;
        }
        while(cur>=0){
            if(arr[cur]!=0){
                arr[des--] = arr[cur--];
            }else {
                arr[des-1] = 0;
                arr[des-2] = 0;
                des-=2;
                cur--;
            }
        }
    }
    //1020
    int[] dx = {0,0,-1,1};
    int[] dy = {1,-1,0,0};
    public int numEnclaves(int[][] grid) {
        Queue<int[]> q = new LinkedList<>();
        int m = grid.length,n = grid[0].length;
        boolean[][] vis = new boolean[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(i==0 || i==m-1 || j==0 || j==n-1){
                    if(grid[i][j]==1){
                        q.add(new int[]{i,j});
                        vis[i][j] = true;
                    }
                }
            }
        }
        while(!q.isEmpty()){
            int[] tmp = q.poll();
            int a = tmp[0],b = tmp[1];
            for (int i = 0; i < 4; i++) {
                int x = a+dx[i];
                int y = b+dy[i];
                if(x>=0 && x<m && y>=0 && y<n && !vis[x][y] && grid[x][y]==1){
                    q.add(new int[]{x,y});
                    vis[x][y] = true;
                }
            }
        }
        int count = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(grid[i][j]==1 && !vis[i][j]){
                    count++;
                }
            }
        }
        return count;
    }
    //202
    public int dou(int n){
        int ret = 0;
        while(n!=0){
            int t = n%10;
            ret = ret+t*t;
            n/=10;
        }
        return ret;
    }
    public boolean isHappy(int n) {
        int slow = n,fast = dou(n);
        while(slow!=fast){
            slow = dou(slow);
            fast = dou(dou(fast));
        }
        return slow==1;
    }
}
